/*
 * @Descripttion:
 * @version:
 * @Author: MichaelHu
 * @Date: 2022-06-30 10:30:55
 * @LastEditors: MichaelHu
 * @LastEditTime: 2022-06-30 10:30:56
 */
package file

import "os"

func WriteToFile(fileName string, content string) error {
	f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
	if err != nil {
		// fmt.Println("file create failed. err: " + err.Error())
	} else {
		// offset
		//os.Truncate(filename, 0) //clear
		// fmt.Println(content)
		n, _ := f.Seek(0, os.SEEK_END)
		_, err = f.WriteAt([]byte(content), n)
		// fmt.Println("write succeed!")
		defer f.Close()
	}
	return err
}
